<!DOCTYPE HTML>
<html>
<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    <title><{config_item('manager_title')}></title>
    <link href="/public/H-ui/css/H-ui.min.css" rel="stylesheet" type="text/css" />
    <link href="/public/H-ui/css/H-ui.admin.css" rel="stylesheet" type="text/css" />
    <link href="/public/H-ui/hui-iconfont/iconfont.css" rel="stylesheet" type="text/css">
</head>
<body>
<div>
    <form action="<{site_url('/manager/goods/model/save')}>" method="post" class="form form-horizontal" id="add" enctype="multipart/form-data">
        <div class="row cl">
            <label class="form-label col-2"><span class="c-red">*</span>模型名称：</label>
            <div class="formControls col-8">
                <input type="text" class="input-text" value="" name="name" datatype="*" nullmsg="请输入模型名称！">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-2"><span class="c-red">*</span>所属分类：</label>
            <div class="formControls col-8">
                <span class="select-box" style="height: 150px;">
				<select name="cat_id[]" class="select" multiple style="height: 140px;">
                    <option value="">请选择分类(可多选)</option>
                    <!--分类模板-->
                    <{function name=type level=0}>
                    <{foreach $data as $key}>
                    <option value="<{$key.id}>" <{if in_array($key.id,$item.cat_id)}>selected<{/if}>><{section name=loop loop=$level}>├<{/section}><{$key.name}></option>
                    <{call name=type data=$key.down level=$level+1}>
                    <{/foreach}>
                    <{/function}>
                    <!--调用模板函数-->
                    <{call name=type data=$cat_list}>
                </select>
				</span>
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-2">
                <button onClick="add_attr();" class="btn btn-primary radius" type="button">添加</button>
            </label>
            <div class="formControls col-9">
                <table class="table table-border table-bordered table-bg table-hover table-sort">
                    <thead>
                    <tr class="text-c">
                        <th width="100">属性</th>
                        <th width="100">类型</th>
                        <th>选择项数据【每项数据之间用逗号','做分割】</th>
                        <th width="80">作为筛选项</th>
                        <th width="50">操作</th>
                    </tr>
                    </thead>
                    <tbody id="model_list">
                    <!--模型列表-->
                    </tbody>
                </table>
                <!--属性模板-->
                <script type='text/html' id='model_attrTemplate'>
                    {{each attr_data}}
                    <tr class="text-c">
                        <td>
                            <input type="hidden" value="{{$value.id}}" name="attr[id][]">
                            <input type="text" class="input-text" value="{{$value.name}}" name="attr[name][]">
                        </td>
                        <td>
                            <span class="select-box">
                                <select name="attr[type][]" class="select">
                                    <option value='1' {{if $value.type=="1"}}selected{{/if}}>单选框</option>
                                    <option value='2' {{if $value.type=="2"}}selected{{/if}}>复选框</option>
                                    <option value='3' {{if $value.type=="3"}}selected{{/if}}>下拉框</option>
                                    <option value='4' {{if $value.type=="4"}}selected{{/if}}>输入框</option>
                                </select>
				            </span>
                        </td>
                        <td><input type="text" class="input-text" value="{{$value.value}}" name="attr[value][]"></td>
                        <td><input type="checkbox" value="1" name="attr[search][]" {{if $value.search=="1"}}checked{{/if}}></td>
                        <td class="f-14">
                            <a onclick="$(this).parent().parent().remove();"><i class="Hui-iconfont">&#xe609;</i></a>
                        </td>
                    </tr>
                    {{/each}}
                </script>
            </div>
        </div>
        <div class="row cl">
            <div class="col-10 col-offset-2">
                <input type="hidden" name="id" value="">
                <button onClick="$('#add').submit();" class="btn btn-primary radius" type="submit"><i class="Hui-iconfont">&#xe632;</i> 保存</button>
                <button onClick="layer_close();" class="btn btn-default radius" type="button">&nbsp;&nbsp;取消&nbsp;&nbsp;</button>
            </div>
        </div>
    </form>
</div>
</div>
<script type="text/javascript" src="/public/js/jquery.js"></script>
<script type="text/javascript" src="/public/js/validform.js"></script>
<script type="text/javascript" src="/public/js/layer/layer.js"></script>
<script type="text/javascript" src="/public/js/form.js"></script>
<script type="text/javascript" src="/public/js/artTemplate.js"></script>
<script type="text/javascript" src="/public/js/ajaxfileupload.js"></script>
<script type="text/javascript" src="/public/H-ui/js/H-ui.js"></script>
<script type="text/javascript" src="/public/H-ui/js/H-ui.admin.js"></script>
<script type="text/javascript">
    $(function(){
        //验证表单
        $.Tipmsg.r=null;
        $("#add").Validform({
            tiptype:function(msg){
                layer.msg(msg);
            },
            tipSweep:true,
            ajaxPost:true,
            callback:function(data){
                if(data.status=="y"){
                layer_close();
                }
            }
        });
        //表单回填
        var formObj = new Form();
        formObj.init(<{ch_json_encode($item)}>);
        <{if $item.attr_data!=''}>
            add_attr(<{ch_json_encode($item)}>);//属性回填
        <{/if}>
    })

    //属性模板解析
    function add_attr(data){
        var data = arguments[0] ? arguments[0] :'';
        if(data=='')
        {
            data = {"attr_data":[""]};
        }
        var html = template('model_attrTemplate', data);
        $('#model_list').append(html);
    }
</script>
</body>
</html>